package com.winit.method.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.winit.common.base.bean.ExecuteResult;
import com.winit.method.mapper.MethodMapper;
import com.winit.method.service.MethodService;
import com.winit.sg.model.Sg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * Created by wanglin on 2018/6/4.
 */
@Component
@Api(value = "method", tags = {"method"}, description = "method")
@RestController
@RequestMapping("/api/v1/method")
public class MethodController {
    @Autowired
    MethodService methodMapper;

    @RequestMapping(value = "/batchSaveMethod", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "保存Method")
    @ResponseBody
    public ExecuteResult batchSaveBean(@RequestBody JSONObject jsonObject){
        ExecuteResult executeResult = new ExecuteResult();
        JSONArray jsonArr = jsonObject.getJSONArray("method");
        methodMapper.batchSgSaveMethod(jsonArr,"SGSE2018060517492000001");
        return executeResult;
    }


    @RequestMapping(value = "/getMethods", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取方法信息")
    @ResponseBody
    public ExecuteResult<Sg> getMethods(
            @ApiParam(value = "id",required=false) @RequestParam(value = "id", required = false) String id,
            @ApiParam(value = "getMethods",required=false) @RequestParam(value = "serviceId", required = false) String serviceId,
            @ApiParam(value = "type",required=true) @RequestParam(value = "type", required = true) String type,
            @ApiParam(value = "是否查固定参数，是：'1' 否：0 默认为：0",required=false) @RequestParam(value = "isParam", required = false) String isParam
    ) {
        ExecuteResult er=new ExecuteResult();
        er.setData(methodMapper.getMethods(id,serviceId,type,isParam));
        return er;
    }




}
